
var globalData = {
    user_id : 48,
    token : "31e23adee5f9b3d16c0767289fcfae00",
    username : "明凯",
}



let init3 = function () {

    $.ajax({
            "url":"/api/activity/v/1",
            "method":"GET",
            data:{
                token:globalData.token,
            },
            success:function (data) {
                console.log(data)
                actRender(data["data"])
            }
        }
    )
}


var actRender = function(data) {


    var tbody = document.createElement("tbody");
    var talkTab = document.getElementById("activityTab")


    for(let i = 0; i < data.length; i++) {

        var atr = document.createElement("tr");
        atr.setAttribute("index", i);

        var atd1 = document.createElement("td");
        atd1.innerHTML = data[i]["id"]

        var atd2 = document.createElement("td");
        atd2.innerHTML = data[i]["name"]

        var atd3 = document.createElement("td");
        atd3.innerHTML =  data[i]["descripe"].substr(0,50)

        var atd4 = document.createElement("td");
        atd4.innerHTML =  data[i]["time"]

        var atd5 = document.createElement("td");
        atd5.innerHTML = data[i]["pics"]

        var atd6 = document.createElement("td");
        atd6.innerHTML = data[i]["joinPeople"].length


        var atd7 = document.createElement("td");

        var abtn = document.createElement("button")
        abtn.setAttribute("class", "deleteBtn");
        abtn.addEventListener("click", function (ev) {

            deleteAct(data[i]["id"]);
        });
        abtn.innerHTML = "删除"
        abtn.classList.add("opeatorBtn")
        atd7.appendChild(abtn)
        atr.append(atd1, atd2, atd3, atd4, atd5, atd6,  atd7)
        tbody.appendChild(atr)

    }



    talkTab.appendChild(tbody)

}




function deleteAct(id) {
    $.ajax({
            "url":"/api/data",
            "method":"post",
            data:{
                token:  globalData.token,
                dataId: 2,
                id:  globalData.user_id ,
                _method  : "delete"},
            success:function (data) {
                alert("删除成功")
                console.log(data)
                init3()
            }
        }
    )
}



window.onload = init3()